﻿using System.Collections.Generic;
using SdmxMl.Common;
using SdmxMl.Structure;

namespace SdmxMl.Excel
{
    /// <summary>
    /// Specialized class for exporting Codelist Artefact in Excel
    /// </summary>
    public class ExcelExportCodeList : ExcelExportFlatHierarchy
    {
        #region Internal members

        private CodeListType clt;

        #endregion

        #region C'tor

        public ExcelExportCodeList(CodeListType c)
        {
            clt = c;
        }
        #endregion

        #region Header generation

        private void GenerateCodelistHeaderNames()
        {
           headerColitems = new List<string>(16);

            headerColitems.Add("Code");
            headerColitems.Add("Parent");
            headerColitems.Add("Level");

            foreach (string lg in SdmxMl.Common.LangSupport.SupportedLanguages)
                headerColitems.Add("Name_" + lg);

            foreach (string lg in SdmxMl.Common.LangSupport.SupportedLanguages)
                headerColitems.Add("Desc_" + lg);

            anInventory = new AnnotationInventory();
            foreach (CodeType c in clt.CodeList)
                anInventory.Inventory(c.AnnotationList, true);

            anInventory.GenerateAnnotationHeader(headerColitems);
        }
        #endregion

        #region Export

        /// <summary> Specialized export for codelists  </summary>
        public override void Export()
        {
            GenerateBook("SMS", "SAE");
            GenerateWorksheetArtefact(clt);
            GenerateCodelistHeaderNames();

            sheet = GenerateWorksheetHeader(
                headerColitems.ToArray(), "Codes", clt.CodeList.Count);

            CreateRows(clt.CodeList);
        }
        #endregion

        #region override

        /// <summary> Specialized description fetching </summary>
        /// <param name="ob">object holding description</param>
        /// <returns>the internationalized description</returns>
        protected override MultiLang GetDescription(object ob)
        {
            MultiLang ml = base.GetDescription(ob);

            
            CodeType c = ob as CodeType;
            if (c != null)
                ml = c.Description;
             
            return ml;
        }
        #endregion

    }
}
